unit RelatorioMovimentoFinancerioCentroCusto;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, UFormRelatorio, DB, DBTables, QRCtrls, QuickRpt, ExtCtrls,
  StdCtrls;

type
  TFRelatorioMovimentoFinanceiroCentroCusto = class(TFormRelatorio)
    Query1: TQuery;
    QRGroup1: TQRGroup;
    QRDBValor: TQRDBText;
    QREDescricao: TQRExpr;
    QRBand2: TQRBand;
    QRDBText5: TQRDBText;
    QRDBText6: TQRDBText;
    QRDBText9: TQRDBText;
    QRDBText11: TQRDBText;
    QRDBValorDetalhe: TQRDBText;
    QRLabel5: TQRLabel;
    QRLabel6: TQRLabel;
    QRLabel7: TQRLabel;
    QRLabel8: TQRLabel;
    QRLabel9: TQRLabel;
    QRLabel10: TQRLabel;
    QRLabel11: TQRLabel;
    QRBand3: TQRBand;
    QRShape2: TQRShape;
    QRLTotal: TQRLabel;
    QRLValorTotal: TQRLabel;
    QRDBTHISTORICO1: TQRDBText;
    QRDBTHISTORICO2: TQRDBText;
    QRDBText1: TQRDBText;
    QRDBText2: TQRDBText;
    QRLabel13: TQRLabel;
    QRLJuros: TQRLabel;
    QRDBValorJuros: TQRDBText;
    QRLabel12: TQRLabel;
    QRDBText3: TQRDBText;
    QRDBText4: TQRDBText;
    QRLabel14: TQRLabel;
    procedure QRGroup1BeforePrint(Sender: TQRCustomBand;
      var PrintBand: Boolean);
    procedure QRBand2BeforePrint(Sender: TQRCustomBand;
      var PrintBand: Boolean);
    procedure FormCreate(Sender: TObject);
    procedure QRBand3BeforePrint(Sender: TQRCustomBand;
      var PrintBand: Boolean);
    procedure QRSysData3Print(sender: TObject; var Value: String);
  private
    { Private declarations }
  public
    { Public declarations }

  end;

var
  FRelatorioMovimentoFinanceiroCentroCusto: TFRelatorioMovimentoFinanceiroCentroCusto;
  Conta,Estrutura:String;
  cont :Integer;
  Valor  :Real;
implementation

uses UGeral;

{$R *.dfm}

procedure TFRelatorioMovimentoFinanceiroCentroCusto.QRGroup1BeforePrint(
  Sender: TQRCustomBand; var PrintBand: Boolean);
begin
  inherited;
 Valor:=0;
 if Estrutura <> Copy(Query1.FieldByName('EstruturaCentro').AsString,1,5) then
  begin
   QRGroup1.Frame.DrawBottom:=true;
   Estrutura:=Copy(Query1.FieldByName('EstruturaCentro').AsString,1,5);
   if cont <> 0 then
    begin
     cont:=0;
     QuickRep1.NewPage;
    end;
   inc(cont);
  end
 else
  QRGroup1.Frame.DrawBottom:=False;

 if (Query1.FieldByName('Conta').AsString = '') or (Estrutura = '') then
  Begin
   QRDBValor.Top:=1;
   QRBand2.Height:=0;
   QRBand3.Height:=1;
  end
 else
  begin
   QRDBValor.Top:=99999999;
   QRBand2.Height:=20;
   QRBand3.Height:=29;
  end;
 QRLTotal.Caption:='Total  ' + Query1.fieldByname('descricaoCentro').AsString + ' :' ;
 QRBand3.Frame.DrawTop:=QRGroup1.Frame.DrawBottom;
end;

procedure TFRelatorioMovimentoFinanceiroCentroCusto.QRBand2BeforePrint(
  Sender: TQRCustomBand; var PrintBand: Boolean);
begin
  inherited;
 if (Conta <> Query1.FieldByName('Conta').AsString) or (Conta = '') then
  Conta:=Query1.FieldByName('Conta').AsString;

 // Formata Campo Historico
 if Query1.fieldByname('Historico2').AsString = '' then
  begin
   QRBand2.Height:= 20;
   QRDBValorDetalhe.Top:=QRDBTHISTORICO1.Top;
  end
 else
  begin
   QRBand2.Height:= 42;
   QRDBValorDetalhe.Top:=QRDBTHISTORICO2.Top;
  end;
 // Fim Formata Campo Historico

 // Formata Juros Multa
 if (Query1.fieldByname('VALORJUROS').AsFloat <> 0) then
  begin
   QRBand2.Height:= 59 ;
   QRLJuros.Width:=82;
   QRDBValorJuros.Width:=68;
  end
 else
  begin
   QRLJuros.Width:=0;
   QRDBValorJuros.Width:=0;
  end;
 // Fim Formata Campo Historico

 if Query1.FieldByName('Conta').AsString = '' then
  Begin
//   QRDBValor.Top:=1;
   QRBand2.Height:=0;
  end;
// else
//  QRDBValor.Top:=18;

 if Query1.fieldByname('Natureza').AsString = 'Entrada' then
  Valor:=valor + (Query1.fieldByname('Valor').AsFloat + Query1.fieldByname('ValorJuros').AsFloat)
 else
 if Query1.fieldByname('Natureza').AsString = 'Saida' then
  Valor:=valor - (Query1.fieldByname('Valor').AsFloat + Query1.fieldByname('ValorJuros').AsFloat) ;
end;

procedure TFRelatorioMovimentoFinanceiroCentroCusto.FormCreate(Sender: TObject);
begin
  inherited;
 Conta:='';
 Estrutura:='';
 cont:=0;

 QRelatorio.Close;
 QRelatorio.SQL.Clear;
 QRelatorio.SQL.Add('Select Emp_Razao as Razao from empresa ');
 QRelatorio.SQL.Add('Where Emp_Codigo = :Cod ');
 QRelatorio.ParamByName('Cod').AsInteger:=Codigoempresa;
 QRelatorio.Open;
 QRLNomeEmpresa.Caption:=QRelatorio.fieldByname('Razao').AsString;

end;

procedure TFRelatorioMovimentoFinanceiroCentroCusto.QRBand3BeforePrint(
  Sender: TQRCustomBand; var PrintBand: Boolean);
begin
  inherited;
 QRLValorTotal.Caption:=FormatFloat('0.,00',valor);
 Valor:=0;
end;

procedure TFRelatorioMovimentoFinanceiroCentroCusto.QRSysData3Print(
  sender: TObject; var Value: String);
begin
  inherited;
value:='';
end;

end.
